package cn.pugle.base;


import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * //druid issue 10380
 *
 * @author tzp
 * @since 2020/9/15
 */
public class NPETest {
    public static class Node {
        long timestamp;
    }

    public static void main(String[] args) {
        Node lhs = new Node();
        Node rhs = new Node();
        int retVal = Long.compare(lhs.timestamp, rhs.timestamp);
        System.out.println(retVal);

        Deque<Node> a = new ConcurrentLinkedDeque<>();//new ArrayDeque<>();array的不让放null
        a.add(lhs);
        Deque<Node> b = new ConcurrentLinkedDeque<>();//cld也不让放null啊
        b.add(rhs);
//        b.add(null);

        List<Deque<Node>> deques = Arrays.asList(a, b);//null

        Stream<Node> sorted = deques.stream()
                .flatMap(Collection::stream)
                .sorted(new Comparator<Node>() {
                    @Override
                    public int compare(Node o1, Node o2) {
                        return Long.compare(lhs.timestamp, rhs.timestamp);
                    }
                });

        sorted.forEach(new Consumer<Node>() {
            @Override
            public void accept(Node node) {
                System.out.println(node.timestamp);
            }
        });
        // Collection<Deque<IncrementalIndexRow>> rowGroups
        //      return rowGroups.stream()
        //                      .flatMap(Collection::stream)
        //                      .sorted(incrementalIndexRowComparator);


        ConcurrentSkipListMap<Node, Node> skipListMap = new ConcurrentSkipListMap<>();
//        skipListMap.put(rhs, null);
//        skipListMap.put(null, lhs);
        skipListMap.put(rhs, rhs);
        skipListMap.get(null);


        //也是k,v都不允许为null
//        ConcurrentHashMap<Node, Node> hashMap = new ConcurrentHashMap<>();
//        hashMap.put(rhs, rhs);
//        hashMap.put(rhs, null);
//        hashMap.get(null);
    }
}
